package org.scc.service;

import java.util.List;

import org.scc.dao.ArticleDao;
import org.scc.model.Article;
import org.scc.vo.PageVO;

public class ArticleService {
	private ArticleDao articleDao;
	public ArticleService(){
		articleDao = new ArticleDao();
	}
	
	public void add(Article article){
		articleDao.add(article);
	}
	
	public PageVO<Article> getPageByUser(int userId, int rowBeginIndex, int rowCount){
		int total = articleDao.selectCountByUser(userId);
		List<Article> articles = articleDao.findByPageUser(userId, rowBeginIndex, rowCount);
		PageVO<Article> pageVO = new PageVO<Article>();
		pageVO.setTotal(total);
		pageVO.setData(articles);
		return pageVO;
	}
	
	public PageVO<Article> findPageByType(int at, int rowBeginIndex, int rowCount){
		PageVO<Article> pageVO = new PageVO<Article>();
		pageVO.setTotal( articleDao.selectCountByType(at) );
		pageVO.setData( articleDao.findPageByType(at, rowBeginIndex, rowCount));
		return pageVO;
	}
	
	public Article load(int id){
		return articleDao.load(id);
	}
	
	public void update(Article article){
		articleDao.update(article);
	}
	
	public void delete(String ids){
		articleDao.delete(ids);
	}
	
	public List<Article> findIndexArticleByType(int at){
		return articleDao.findIndexArticleByType(at);
	}
}
